<?php

namespace app\admin\controller\sms;

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
use AlibabaCloud\Tea\Model;
use app\common\controller\Backend;
use Darabonba\OpenApi\Models\Config;
class Sms extends Backend {

    protected $noNeedLogin = [
        'getsmscode'
    ];
    public function getSmsCode () {
        $client = self::createClient("LTAI5tQj4m22Bm8cpmapeZyE", "dSqkoHqBnUpNKDOIEhyDlhCj1kpVMp");
        $sendSmsRequest = new SendSmsRequest([]);
        $sendSmsRequest->phoneNumbers='13145208156';
        $sendSmsRequest->signName='';
        $sendSmsRequest->templateCode='';
        // 复制代码运行请自行打印 API 的返回值
        $client->sendSms($sendSmsRequest);
    }

    /**
     * 使用AK&SK初始化账号Client
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Dysmsapi Client
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        $config = new Config([
            // 您的AccessKey ID
            "accessKeyId" => $accessKeyId,
            // 您的AccessKey Secret
            "accessKeySecret" => $accessKeySecret
        ]);
        // 访问的域名
        $config->endpoint = "dysmsapi.aliyuncs.com";
        return new Dysmsapi($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        $client = self::createClient("LTAI5tQj4m22Bm8cpmapeZyE", "dSqkoHqBnUpNKDOIEhyDlhCj1kpVMp");
        $sendSmsRequest = new SendSmsRequest([]);
        // 复制代码运行请自行打印 API 的返回值
        $client->sendSms($sendSmsRequest);
    }
}